package com.run.cat.service.impl;

import com.run.cat.common.base.BaseResult;
import com.run.cat.common.base.BaseServiceImpl;
import com.run.cat.common.util.DateUtils;
import com.run.cat.common.util.EmptyUtil;
import com.run.cat.common.util.MyBeanUtils;
import com.run.cat.dao.dto.RegisterDto;
import com.run.cat.dao.entity.Register;
import com.run.cat.dao.mapper.RegisterMapper;
import com.run.cat.service.IRegisterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author CG
 * @since 2020-08-19
 */
@Service
public class RegisterServiceImpl extends BaseServiceImpl<RegisterMapper, Register> implements IRegisterService {


    @Override
    public BaseResult checkRegister(RegisterDto dto) {
        Register register = this.queryOne(new Register().setPhone(dto.getPhone()));
        if(EmptyUtil.isNotEmpty(register))
            return BaseResult.failMsg("用户手机号已注册");

        return BaseResult.success();
    }

    @Override
    @Transactional
    public BaseResult register(RegisterDto vo, String salt) {
        Register register = MyBeanUtils.copyBean(vo,Register.class);
        register.setSalt(salt);
        register.setCreateTime(DateUtils.getSysDate());
        insert(register);
        return BaseResult.success();
    }
}
